﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.QcManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.QcManagement.QcSheetVMs
{
    public partial class QcSheetListVM : BasePagedListVM<QcSheet_View, QcSheetSearcher>
    {
        
        protected override IEnumerable<IGridColumn<QcSheet_View>> InitGridHeader()
        {
            return new List<GridColumn<QcSheet_View>>{
                
                this.MakeGridHeader(x => x.QcSheet_WoId).SetTitle(@Localizer["Page.工单号"].Value),
                this.MakeGridHeader(x => x.QcSheet_WoCode).SetTitle(@Localizer["Page.工单编号"].Value),
                this.MakeGridHeader(x => x.QcSheet_ProductId).SetTitle(@Localizer["Page.产品"].Value),
                this.MakeGridHeader(x => x.QcSheet_ProductName).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.QcSheet_QcMode).SetTitle(@Localizer["Page.质检模式"].Value),
                this.MakeGridHeader(x => x.QcSheet_Sn).SetTitle(@Localizer["Page.追溯码"].Value),
                this.MakeGridHeader(x => x.QcSheet_Template).SetTitle(@Localizer["Page.检验模板"].Value),
                this.MakeGridHeader(x => x.QcSheet_QcOperator).SetTitle(@Localizer["Page.检验员"].Value),
                this.MakeGridHeader(x => x.QcSheet_QcResult).SetTitle(@Localizer["Page.检验结果"].Value),
                this.MakeGridHeader(x => x.QcSheet_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),
                this.MakeGridHeader(x => x.QcSheet_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.QcSheet_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.QcSheet_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.QcSheet_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<QcSheet_View> GetSearchQuery()
        {
            var query = DC.Set<QcSheet>()
                
                .CheckEqual(Searcher.WoId, x=>x.WoId)
                .CheckContain(Searcher.WoCode, x=>x.WoCode)
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckContain(Searcher.ProductName, x=>x.ProductName)
                .CheckEqual(Searcher.QcMode, x=>x.QcMode)
                .CheckContain(Searcher.Sn, x=>x.Sn)
                .CheckEqual(Searcher.TemplateId, x=>x.TemplateId)
                .CheckContain(Searcher.QcOperator, x=>x.QcOperator)
                .CheckEqual(Searcher.QcResult, x=>x.QcResult)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new QcSheet_View
                {
				    ID = x.ID,
                    
                    QcSheet_WoId = x.WoId,
                    QcSheet_WoCode = x.WoCode,
                    QcSheet_ProductId = x.ProductId,
                    QcSheet_ProductName = x.ProductName,
                    QcSheet_QcMode = x.QcMode,
                    QcSheet_Sn = x.Sn,
                    QcSheet_Template = x.Template.TenantCode,
                    QcSheet_QcOperator = x.QcOperator,
                    QcSheet_QcResult = x.QcResult,
                    QcSheet_Remark = x.Remark,
                    QcSheet_CreateTime = x.CreateTime,
                    QcSheet_UpdateTime = x.UpdateTime,
                    QcSheet_CreateBy = x.CreateBy,
                    QcSheet_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class QcSheet_View: QcSheet
    {
        
        public long? QcSheet_WoId { get; set; }
        public string QcSheet_WoCode { get; set; }
        public long? QcSheet_ProductId { get; set; }
        public string QcSheet_ProductName { get; set; }
        public QcModeEnum? QcSheet_QcMode { get; set; }
        public string QcSheet_Sn { get; set; }
        public string QcSheet_Template { get; set; }
        public string QcSheet_QcOperator { get; set; }
        public QcStatusEnum? QcSheet_QcResult { get; set; }
        public string QcSheet_Remark { get; set; }
        public DateTime? QcSheet_CreateTime { get; set; }
        public DateTime? QcSheet_UpdateTime { get; set; }
        public string QcSheet_CreateBy { get; set; }
        public string QcSheet_UpdateBy { get; set; }

    }

}